package com.mz.ozy.mvp.presenter;


import android.app.Activity;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.AboutBean;
import com.mz.ozy.mvp.model.ModifyPwdModel;
import com.mz.ozy.mvp.view.ModifyPwdContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class ModifyPwdPresenter extends BasePresenterImpl<ModifyPwdContract.View> implements ModifyPwdContract.Presenter {

    private ModifyPwdModel mModel;

    public ModifyPwdPresenter() {
        mModel = new ModifyPwdModel();
    }


    @Override
    public void getCode(Activity activity, String mobilePhone) {
        mModel.getCode(activity, mobilePhone)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.getCodeSuccess(jsonObject);
                    }

                });

    }

    @Override
    public void getAbout(Activity activity) {
        mModel.about(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<AboutBean>(mView) {
                    @Override
                    public void onSuccesss(AboutBean jsonObject) {
                        mView.getSuccess(jsonObject);
                    }

                });
    }

    @Override
    public void obtainModifyPwd(Activity activity, String pwdflag, String code, String newpwd) {
        mModel.obtainModifyPwd(activity, pwdflag, code, newpwd)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.obtainModifyPwdSuccess(jsonObject);
                    }

                });

    }
}
